package com.kyxx.mycommonproject.shangpinxiangqing;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;

import com.kyxx.mycommonproject.R;
import com.kyxx.mycommonproject.base.BaseActivity0;
import com.kyxx.mycommonproject.wodedingdan.TabFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class GoodDetailActivity extends BaseActivity0 {
    private TabLayout tl;
    private ViewPager vp;
    private String[] titles = new String[]{"商品", "详情", "评论"};

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_good_detail);
    }

    @Override
    protected void findViewById() {
        tl = (TabLayout) findViewById(R.id.tl);
        vp = (ViewPager) findViewById(R.id.vp);
    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void processLogic() {
        loadToolBar("商品详情");
        List<Fragment> fragments = new ArrayList<Fragment>();
        GoodDetailGoodFragment goodDetailGoodFragment = new GoodDetailGoodFragment();
        fragments.add(goodDetailGoodFragment);
        GoodDetailDetailFragment goodDetailDetailFragment = new GoodDetailDetailFragment();
        fragments.add(goodDetailDetailFragment);
        GoodDetailValueFragment goodDetailValueFragment = new GoodDetailValueFragment();
        fragments.add(goodDetailValueFragment);
        vp.setAdapter(new TabFragmentAdapter(fragments, titles, getSupportFragmentManager(), context));
        tl.setupWithViewPager(vp);
        tl.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tab.getPosition(), false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.good_detail_menu, menu);
        return true;
    }
}
